﻿' Code from http://forum.xda-developers.com/showthread.php?t=264497 and translated into VB.Net
' Credit to crusieUser for C# code.

Imports System.Runtime.InteropServices

Public Class SetProfile
  Private Enum SND_SOUNDTYPE
    [On]
    File
    Vibrate
    None
  End Enum

  Private Enum SND_EVENT
    All
    RingLine1
    RingLine2
    KnownCallerLine1
    RoamingLine1
    RingVoip
  End Enum

  <StructLayout(LayoutKind.Sequential)> _
  Private Structure SNDFILEINFO
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
    Public szPathName As String
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
    Public szDisplayName As String
    Public sstType As SND_SOUNDTYPE
  End Structure

  <DllImport("coredll.dll")> _
  Private Shared Sub AudioUpdateFromRegistry()
  End Sub

  <DllImport("aygshell.dll", SetLastError:=True)> _
  Private Shared Function SndSetSound(ByVal seSoundEvent As SND_EVENT, ByRef pSoundFileInfo As SNDFILEINFO, ByVal fSuppressUI As Boolean) As UInteger
  End Function

  Public Shared Sub SetProfileNormal()
    Dim soundFileInfo As New SNDFILEINFO()
    soundFileInfo.sstType = SND_SOUNDTYPE.[On]
    SndSetSound(SND_EVENT.All, soundFileInfo, True)
    AudioUpdateFromRegistry()
  End Sub

  Public Shared Sub SetProfileVibrate()
    Dim soundFileInfo As New SNDFILEINFO()
    soundFileInfo.sstType = SND_SOUNDTYPE.Vibrate
    SndSetSound(SND_EVENT.All, soundFileInfo, True)
    AudioUpdateFromRegistry()
  End Sub

  Public Shared Sub SetProfileMuted()
    Dim soundFileInfo As New SNDFILEINFO()
    soundFileInfo.sstType = SND_SOUNDTYPE.None
    SndSetSound(SND_EVENT.All, soundFileInfo, True)
    AudioUpdateFromRegistry()
  End Sub
End Class
